<?php

namespace app\common\model;

use think\facade\Db;
use think\Model;

class Classwork extends Model
{
    //自动生成写入时间
    protected $autoWriteTimestamp = true;

    public function classwork($data)
    {

        if (empty($data['subject_id'])) {
            return Db::table('classwork')
                ->alias('c')
                ->join('subject s', 'c.subject_id = s.id')
                ->field('c.*,s.name as subject_name')
                ->paginate($data);
        } else {
            return Db::table('classwork')
                ->alias('c')
                ->join('subject s', 'c.subject_id = s.id')
                ->field('c.*,s.name as subject_name')
                ->where(['c.subject_id' => $data['subject_id']])
                ->paginate($data);
        }
    }
}